<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    *{
      margin: 0;
    }
    #myDiv{
      width: 200px;
      height: 200px;
      background-color: pink;
      position: absolute;
      left:0;
      top:0;
    }
  </style>
</head>
<body>
  <div id="myDiv"></div>
  <script>
    var myDiv = document.getElementById('myDiv')
    var t = setInterval(function(){
      myDiv.style.left = myDiv.offsetLeft + 1 + 'px'
      // 判断div的左侧马上要超出边界
      if (document.documentElement.offsetWidth - myDiv.offsetWidth <= myDiv.offsetLeft) {
        clearInterval(t)
      }
    },10)
  </script>
</body>
</html>